﻿
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using More.Engine;
using More.Engine.Evaluation;
using More.Engine.Model;
namespace Rules112014
{
    public class CompiledRuleBookFactory : CompiledRuleBookFactoryBase
    {
        private DateTime? _effectiveDate;
        public override DateTime? EffectiveDate
        {
            get
            {
                return _effectiveDate ?? (_effectiveDate = DateTime.Parse("1/1/2014 12:00:00 AM"));
            }
        }
        public override CompiledRuleBookBase GetRuleBook(string name)
        {

            if (name.Equals("MikesTestBook"))
            {
                return new MikesTestBookRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("CCI_TierFactor"))
            {
                return new CCI_TierFactorRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("Underwriting_Workstation_Binding_Checklist"))
            {
                return new Underwriting_Workstation_Binding_ChecklistRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("Rating_CW"))
            {
                return new Rating_CWRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("Liability_CW"))
            {
                return new Liability_CWRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("DriverGrading"))
            {
                return new DriverGradingRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            if (name.Equals("DriverGrading_Liability"))
            {
                return new DriverGrading_LiabilityRuleBook() { Factory = this, TableRepository = LookupTablesRepository };
            }
            return null;
        }
    }


    public class MikesTestBookRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield return new InputRequirement() { Name = "age" };
            yield return new InputRequirement() { Name = "points" };
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {

            if (true)
            {
                ConditionEntered("DriverValidation");
                var age = GetInput("age");
                var points = GetInput("points");

                var AgeCheck =
                    StatementExecuted("17", "AgeCheck", "AgeCheck", "age <= 70 and age > 17",
                         () => { return Convert.ToBoolean((Convert.ToDouble((age)) <= Convert.ToDouble(70))) && Convert.ToBoolean((Convert.ToDouble((age)) > Convert.ToDouble(17))); } // <------- AgeCheck
                         );


                var PointsCheck =
                    StatementExecuted("19", "PointsCheck", "PointsCheck", "points <= 7",
                         () => { return Convert.ToDouble((points)) <= Convert.ToDouble(7); } // <------- PointsCheck
                         );


                var Final =
                    StatementExecuted("15", "Final", "Final", "AgeCheck and PointsCheck",
                         () => { return Convert.ToBoolean((AgeCheck)) && Convert.ToBoolean((PointsCheck)); } // <------- Final
                         );

                ConditionExited("DriverValidation");
            }

            return Result;
        }





    }
    public class CCI_TierFactorRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield return new InputRequirement() { Name = "insuredCreditScore" };
            yield return new InputRequirement() { Name = "referenceId" };
            yield return new InputRequirement() { Name = "age" };
            yield return new InputRequirement() { Name = "yearsExperience" };
            yield return new InputRequirement() { Name = "yearsWithCurrentEmployer" };
            yield return new InputRequirement() { Name = "numberOfMinors" };
            yield return new InputRequirement() { Name = "numberOfPoints" };
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {

            if (true)
            {
                ConditionEntered("CalculateTierFactor");
                var insuredCreditScore = GetInput("insuredCreditScore");

                var CreditTier =
                    StatementExecuted("220", "CreditTier", "CreditTier", "RuleEngineUser_CCI_CreditTier(\'Tier\', insuredCreditScore)",
                         () => { return RuleEngineUser_CCI_CreditTier("Tier", insuredCreditScore); } // <------- CreditTier
                         );


                var Drivers = GetInput("drivers");
                if (true)
                {
                    ConditionEntered("Drivers");
                    LoopEntered("Drivers", "drivers");
                    var drivers = GetInput("drivers");

                    var DriversItemIndex = 0;
                    foreach (IDictionary<string, object> DriversItem in (IList)drivers)
                    {
                        LoopItemEntered(DriversItemIndex, "Drivers", "drivers", DriversItem);
                        var referenceId = GetInput("referenceId");
                        var age = GetInput("age");
                        var yearsExperience = GetInput("yearsExperience");
                        var yearsWithCurrentEmployer = GetInput("yearsWithCurrentEmployer");
                        var numberOfMinors = GetInput("numberOfMinors");
                        var numberOfPoints = GetInput("numberOfPoints");

                        var CorrelationId =
                            StatementExecuted("35", "CorrelationId", "CorrelationId", "referenceId",
                                 () => { return referenceId; } // <------- CorrelationId
                                 );


                        var AgeTier =
                            StatementExecuted("223", "AgeTier", "AgeTier", "RuleEngineUser_CCI_AgeTier(\'Tier\', age)",
                                 () => { return RuleEngineUser_CCI_AgeTier("Tier", age); } // <------- AgeTier
                                 );


                        var DrivingExperienceTier =
                            StatementExecuted("224", "DrivingExperienceTier", "DrivingExperienceTier", "RuleEngineUser_CCI_DrivingExpTier(\'Tier\', yearsExperience)",
                                 () => { return RuleEngineUser_CCI_DrivingExpTier("Tier", yearsExperience); } // <------- DrivingExperienceTier
                                 );


                        var YearsWithCurrentEmployerTier =
                            StatementExecuted("225", "YearsWithCurrentEmployerTier", "YearsWithCurrentEmployerTier", "RuleEngineUser_CCI_YearsWithCurrentEmployerTier(\'Tier\', yearsWithCurrentEmployer)" +
                    "",
                                 () => { return RuleEngineUser_CCI_YearsWithCurrentEmployerTier("Tier", yearsWithCurrentEmployer); } // <------- YearsWithCurrentEmployerTier
                                 );


                        var NumberOfMinorsTier =
                            StatementExecuted("226", "NumberOfMinorsTier", "NumberOfMinorsTier", "numberOfMinors < 0 ? 3 : RuleEngineUser_CCI_NumberMinorsTier(\'Tier\', numberOfMino" +
                    "rs)",
                                 () => { return (bool)(Convert.ToDouble((numberOfMinors)) < Convert.ToDouble(0)) ? 3 : (RuleEngineUser_CCI_NumberMinorsTier("Tier", numberOfMinors)); } // <------- NumberOfMinorsTier
                                 );


                        var NumberOfPointsTier =
                            StatementExecuted("227", "NumberOfPointsTier", "NumberOfPointsTier", "numberOfPoints < 0 ? 3 : RuleEngineUser_CCI_NumberPointsTier(\'Tier\', numberOfPoin" +
                    "ts)",
                                 () => { return (bool)(Convert.ToDouble((numberOfPoints)) < Convert.ToDouble(0)) ? 3 : (RuleEngineUser_CCI_NumberPointsTier("Tier", numberOfPoints)); } // <------- NumberOfPointsTier
                                 );


                        var TierAverage =
                            StatementExecuted("28", "TierAverage", "TierAverage", "(AgeTier + CreditTier + DrivingExperienceTier + NumberOfMinorsTier + NumberOfPoin" +
                    "tsTier + YearsWithCurrentEmployerTier) / 6",
                                 () => { return Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((AgeTier)) + Convert.ToDouble((CreditTier)))) + Convert.ToDouble((DrivingExperienceTier)))) + Convert.ToDouble((NumberOfMinorsTier)))) + Convert.ToDouble((NumberOfPointsTier)))) + Convert.ToDouble((YearsWithCurrentEmployerTier)))) / Convert.ToDouble(6); } // <------- TierAverage
                                 );

                        LoopItemExited(DriversItemIndex, "Drivers", "drivers");
                        DriversItemIndex++;
                    }
                    LoopExited("Drivers", "drivers");
                    ConditionExited("Drivers");
                }


                var OverallAverageTier =
                    StatementExecuted("42", "OverallAverageTier", "OverallAverageTier", "Sum(Drivers, \'TierAverage\') / Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "TierAverage"))) / Convert.ToDouble((Count(Drivers))); } // <------- OverallAverageTier
                         );


                var OverallTier =
                    StatementExecuted("43", "OverallTier", "OverallTier", "Round(OverallAverageTier, 0)",
                         () => { return Round(OverallAverageTier, 0); } // <------- OverallTier
                         );


                var OverallTierDiff =
                    StatementExecuted("90", "OverallTierDiff", "OverallTierDiff", "Round(OverallTier - OverallAverageTier, 1)",
                         () => { return Round(Convert.ToDouble((OverallTier)) - Convert.ToDouble((OverallAverageTier)), 1); } // <------- OverallTierDiff
                         );


                var TierFactorTier =
                    StatementExecuted("221", "TierFactorTier", "TierFactorTier", "RuleEngineUser_CCI_TierFactor(\'Factor\', OverallTier)",
                         () => { return RuleEngineUser_CCI_TierFactor("Factor", OverallTier); } // <------- TierFactorTier
                         );


                var TierAdjustmentFactor =
                    StatementExecuted("222", "TierAdjustmentFactor", "TierAdjustmentFactor", "RuleEngineUser_CCI_TierAdjustmentFactor(\'Factor\', OverallTierDiff)",
                         () => { return RuleEngineUser_CCI_TierAdjustmentFactor("Factor", OverallTierDiff); } // <------- TierAdjustmentFactor
                         );


                var TierFactor =
                    StatementExecuted("41", "TierFactor", "TierFactor", "TierFactorTier * TierAdjustmentFactor",
                         () => { return Convert.ToDouble((TierFactorTier)) * Convert.ToDouble((TierAdjustmentFactor)); } // <------- TierFactor
                         );

                ConditionExited("CalculateTierFactor");
            }

            return Result;
        }





    }
    public class Underwriting_Workstation_Binding_ChecklistRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield return new InputRequirement() { Name = "Drivers" };
            yield return new InputRequirement() { Name = "RadiusCredit" };
            yield return new InputRequirement() { Name = "Referral" };
            yield return new InputRequirement() { Name = "CargoRelated" };
            yield return new InputRequirement() { Name = "CrashIndicator" };
            yield return new InputRequirement() { Name = "DriverFitness" };
            yield return new InputRequirement() { Name = "DrugsAlcohol" };
            yield return new InputRequirement() { Name = "FatiguedDriving" };
            yield return new InputRequirement() { Name = "UnSafeDriving" };
            yield return new InputRequirement() { Name = "VehicleMaintenance" };
            yield return new InputRequirement() { Name = "PowerUnits" };
            yield return new InputRequirement() { Name = "CoverageSummary" };
            yield return new InputRequirement() { Name = "EffectiveDate" };
            yield return new InputRequirement() { Name = "BusinessStartDate" };
            yield return new InputRequirement() { Name = "CoverageHistory" };
            yield return new InputRequirement() { Name = "CommoditiesHauled" };
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {

            if (true)
            {
                ConditionEntered("ChecklistRules");
                var Drivers = GetInput("Drivers");
                var RadiusCredit = GetInput("RadiusCredit");
                var Referral = GetInput("Referral");
                var CargoRelated = GetInput("CargoRelated");
                var CrashIndicator = GetInput("CrashIndicator");
                var DriverFitness = GetInput("DriverFitness");
                var DrugsAlcohol = GetInput("DrugsAlcohol");
                var FatiguedDriving = GetInput("FatiguedDriving");
                var UnSafeDriving = GetInput("UnSafeDriving");
                var VehicleMaintenance = GetInput("VehicleMaintenance");
                var PowerUnits = GetInput("PowerUnits");
                var CoverageSummary = GetInput("CoverageSummary");
                var EffectiveDate = GetInput("EffectiveDate");
                var BusinessStartDate = GetInput("BusinessStartDate");
                var CoverageHistory = GetInput("CoverageHistory");
                var CommoditiesHauled = GetInput("CommoditiesHauled");

                var MvrPointsCount =
                    StatementExecuted("51", "MvrPointsCount", "MvrPointsCount", "Sum(Drivers, \'Points\')",
                         () => { return Sum(Drivers, "Points"); } // <------- MvrPointsCount
                         );


                var DriverAgeThreshold =
                    StatementExecuted("53", "DriverAgeThreshold", "DriverAgeThreshold", "Min(Drivers,\'Age\') < 23 || Max(Drivers,\'Age\') > 70",
                         () => { return Convert.ToBoolean((Convert.ToDouble((Min(Drivers, "Age"))) < Convert.ToDouble(23))) || Convert.ToBoolean((Convert.ToDouble((Max(Drivers, "Age"))) > Convert.ToDouble(70))); } // <------- DriverAgeThreshold
                         );


                var CreditsNoReferral =
                    StatementExecuted("55", "CreditsNoReferral", "CreditsNoReferral", "RadiusCredit != \'\' && Referral == \'\'",
                         () => { return Convert.ToBoolean((!((RadiusCredit).Equals("")))) && Convert.ToBoolean(((Referral).Equals(""))); } // <------- CreditsNoReferral
                         );


                var DriverThreshold =
                    StatementExecuted("56", "DriverThreshold", "DriverThreshold", "DriverAgeThreshold || MvrPointsCount > 9",
                         () => { return Convert.ToBoolean((DriverAgeThreshold)) || Convert.ToBoolean((Convert.ToDouble((MvrPointsCount)) > Convert.ToDouble(9))); } // <------- DriverThreshold
                         );


                var SMSAlert =
                    StatementExecuted("57", "SMSAlert", "SMSAlert", "CargoRelated || CrashIndicator || DriverFitness || DrugsAlcohol || FatiguedDrivin" +
            "g || UnSafeDriving || VehicleMaintenance",
                         () => { return Convert.ToBoolean((CargoRelated)) || Convert.ToBoolean((Convert.ToBoolean((CrashIndicator)) || Convert.ToBoolean((Convert.ToBoolean((DriverFitness)) || Convert.ToBoolean((Convert.ToBoolean((DrugsAlcohol)) || Convert.ToBoolean((Convert.ToBoolean((FatiguedDriving)) || Convert.ToBoolean((Convert.ToBoolean((UnSafeDriving)) || Convert.ToBoolean((VehicleMaintenance)))))))))))); } // <------- SMSAlert
                         );


                var PowerUnitCount =
                    StatementExecuted("61", "PowerUnitCount", "PowerUnitCount", "PowerUnits",
                         () => { return PowerUnits; } // <------- PowerUnitCount
                         );


                var LossIncomplete =
                    StatementExecuted("63", "LossIncomplete", "LossIncomplete", "Min(CoverageSummary, \'TermYear\') < 5 || Count(CoverageSummary) < 3",
                         () => { return Convert.ToBoolean((Convert.ToDouble((Min(CoverageSummary, "TermYear"))) < Convert.ToDouble(5))) || Convert.ToBoolean((Convert.ToDouble((Count(CoverageSummary))) < Convert.ToDouble(3))); } // <------- LossIncomplete
                         );


                var NewVentures =
                    StatementExecuted("67", "NewVentures", "NewVentures", "TotalYears(DateDiff(EffectiveDate, BusinessStartDate)) <= 2",
                         () => { return Convert.ToDouble((TotalYears(DateDiff(EffectiveDate, BusinessStartDate)))) <= Convert.ToDouble(2); } // <------- NewVentures
                         );


                var LossThreshold =
                    StatementExecuted("91", "LossThreshold", "LossThreshold", "Max(CoverageSummary, \'Ratio\') > 50",
                         () => { return Convert.ToDouble((Max(CoverageSummary, "Ratio"))) > Convert.ToDouble(50); } // <------- LossThreshold
                         );


                var LossOverThreshold =
                    StatementExecuted("92", "LossOverThreshold", "LossOverThreshold", "Max(CoverageHistory, \'Amount\') > 25000",
                         () => { return Convert.ToDouble((Max(CoverageHistory, "Amount"))) > Convert.ToDouble(25000); } // <------- LossOverThreshold
                         );


                var CommodityRating =
                    StatementExecuted("228", "CommodityRating", "CommodityRating", "RuleEngineUser_CCI_Commodities(\'Zone\', CommoditiesHauled)",
                         () => { return RuleEngineUser_CCI_Commodities("Zone", CommoditiesHauled); } // <------- CommodityRating
                         );


                var RiskThreshold =
                    StatementExecuted("58", "RiskThreshold", "RiskThreshold", "(PowerUnitCount > 1 || MvrPointsCount > 6) && NewVentures",
                         () => { return Convert.ToBoolean((Convert.ToBoolean((Convert.ToDouble((PowerUnitCount)) > Convert.ToDouble(1))) || Convert.ToBoolean((Convert.ToDouble((MvrPointsCount)) > Convert.ToDouble(6))))) && Convert.ToBoolean((NewVentures)); } // <------- RiskThreshold
                         );


                var CommodityThreshold =
                    StatementExecuted("66", "CommodityThreshold", "CommodityThreshold", "CommodityRating == 4 || CommodityRating == 5",
                         () => { return Convert.ToBoolean(((CommodityRating).Equals(4))) || Convert.ToBoolean(((CommodityRating).Equals(5))); } // <------- CommodityThreshold
                         );

                ConditionExited("ChecklistRules");
            }

            return Result;
        }





    }
    public class Rating_CWRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield break;
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {
            return Result;
        }





    }
    public class Liability_CWRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield break;
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {
            return Result;
        }





    }
    public class DriverGradingRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield return new InputRequirement() { Name = "businessType" };
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {

            if (true)
            {
                ConditionEntered("CalculateDriverGrade");
                var businessType = GetInput("businessType");

                if (!((businessType).Equals("Brokerage")))
                {
                    ConditionEntered("Coverages");

                    var LiabilityCoverage =
                        StatementExecuted("191", "LiabilityCoverage", "LiabilityCoverage", "DriverGrading_Liability()",
                             () => { return DriverGrading_Liability(); } // <------- LiabilityCoverage
                             );


                    var LiabilityFactor =
                        StatementExecuted("258", "LiabilityFactor", "LiabilityFactor", "[LiabilityCoverage:IsLiability:FinalLiabilityFactor] >= 0 ? 1 : 2",
                             () => { return (bool)(Convert.ToDouble((GetInput("LiabilityCoverage", "IsLiability", "FinalLiabilityFactor"))) >= Convert.ToDouble(0)) ? 1 : 2; } // <------- LiabilityFactor
                             );

                    ConditionExited("Coverages");
                }

                ConditionExited("CalculateDriverGrade");
            }

            return Result;
        }





    }
    public class DriverGrading_LiabilityRuleBook : CommonRuleBook
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield return new InputRequirement() { Name = "age" };
            yield return new InputRequirement() { Name = "yearsWithEmployer" };
            yield return new InputRequirement() { Name = "yearsExperience" };
            yield return new InputRequirement() { Name = "numberOfPoints" };
            yield return new InputRequirement() { Name = "numberOfMinors" };
            yield return new InputRequirement() { Name = "restriction" };
            yield return new InputRequirement() { Name = "referenceId" };
            yield return new InputRequirement() { Name = "attractScoreType" };
            yield return new InputRequirement() { Name = "attractScore" };
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {

            if (true)
            {
                ConditionEntered("IsLiability");
                var attractScoreType = GetInput("attractScoreType");
                var attractScore = GetInput("attractScore");

                var Drivers = GetInput("drivers");
                if (true)
                {
                    ConditionEntered("Drivers");
                    LoopEntered("Drivers", "drivers");
                    var drivers = GetInput("drivers");

                    var DriversItemIndex = 0;
                    foreach (IDictionary<string, object> DriversItem in (IList)drivers)
                    {
                        LoopItemEntered(DriversItemIndex, "Drivers", "drivers", DriversItem);
                        var age = GetInput("age");
                        var yearsWithEmployer = GetInput("yearsWithEmployer");
                        var yearsExperience = GetInput("yearsExperience");
                        var numberOfPoints = GetInput("numberOfPoints");
                        var numberOfMinors = GetInput("numberOfMinors");
                        var restriction = GetInput("restriction");
                        var referenceId = GetInput("referenceId");

                        var LiabilityAgeFactor =
                            StatementExecuted("238", "LiabilityAgeFactor", "LiabilityAgeFactor", "RuleEngineUser_CCI_AgeFactor(\'AutoLiabilityFactor\', age)",
                                 () => { return RuleEngineUser_CCI_AgeFactor("AutoLiabilityFactor", age); } // <------- LiabilityAgeFactor
                                 );


                        var LiabilityYearsWithEmployerFactor =
                            StatementExecuted("239", "LiabilityYearsWithEmployerFactor", "LiabilityYearsWithEmployerFactor", "RuleEngineUser_CCI_YearsWithCurrentEmployerFactor(\'AutoLiabilityFactor\', yearsWit" +
                    "hEmployer)",
                                 () => { return RuleEngineUser_CCI_YearsWithCurrentEmployerFactor("AutoLiabilityFactor", yearsWithEmployer); } // <------- LiabilityYearsWithEmployerFactor
                                 );


                        var LiabilityDrivingExperienceFactor =
                            StatementExecuted("240", "LiabilityDrivingExperienceFactor", "LiabilityDrivingExperienceFactor", "RuleEngineUser_CCI_YearsDrivingExperienceFactor(\'AutoLiabilityFactor\', yearsExper" +
                    "ience)",
                                 () => { return RuleEngineUser_CCI_YearsDrivingExperienceFactor("AutoLiabilityFactor", yearsExperience); } // <------- LiabilityDrivingExperienceFactor
                                 );


                        var LiabilityPointsFactor =
                            StatementExecuted("241", "LiabilityPointsFactor", "LiabilityPointsFactor", "RuleEngineUser_CCI_NumberOfPointsFactor(\'AutoLiabilityFactor\', numberOfPoints)",
                                 () => { return RuleEngineUser_CCI_NumberOfPointsFactor("AutoLiabilityFactor", numberOfPoints); } // <------- LiabilityPointsFactor
                                 );


                        var LiabilityMinorsFactor =
                            StatementExecuted("242", "LiabilityMinorsFactor", "LiabilityMinorsFactor", "RuleEngineUser_CCI_NumberOfMinorsFactor(\'AutoLiabilityFactor\', numberOfMinors)",
                                 () => { return RuleEngineUser_CCI_NumberOfMinorsFactor("AutoLiabilityFactor", numberOfMinors); } // <------- LiabilityMinorsFactor
                                 );


                        var LiabilityLicenseRestrictionFactor =
                            StatementExecuted("243", "LiabilityLicenseRestrictionFactor", "LiabilityLicenseRestrictionFactor", "RuleEngineUser_CCI_DriverLicenseRestrictionFactor(\'AutoLiabilityFactor\', restrict" +
                    "ion)",
                                 () => { return RuleEngineUser_CCI_DriverLicenseRestrictionFactor("AutoLiabilityFactor", restriction); } // <------- LiabilityLicenseRestrictionFactor
                                 );


                        var LiabilityDriverCoverageFactor =
                            StatementExecuted("244", "LiabilityDriverCoverageFactor", "LiabilityDriverCoverageFactor", "(LiabilityAgeFactor * LiabilityYearsWithEmployerFactor * LiabilityDrivingExperien" +
                    "ceFactor * LiabilityPointsFactor * LiabilityMinorsFactor * LiabilityLicenseRestr" +
                    "ictionFactor)",
                                 () => { return Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((Convert.ToDouble((LiabilityAgeFactor)) * Convert.ToDouble((LiabilityYearsWithEmployerFactor)))) * Convert.ToDouble((LiabilityDrivingExperienceFactor)))) * Convert.ToDouble((LiabilityPointsFactor)))) * Convert.ToDouble((LiabilityMinorsFactor)))) * Convert.ToDouble((LiabilityLicenseRestrictionFactor)); } // <------- LiabilityDriverCoverageFactor
                                 );


                        var ReferenceId =
                            StatementExecuted("245", "ReferenceId", "ReferenceId", "referenceId",
                                 () => { return referenceId; } // <------- ReferenceId
                                 );

                        LoopItemExited(DriversItemIndex, "Drivers", "drivers");
                        DriversItemIndex++;
                    }
                    LoopExited("Drivers", "drivers");
                    ConditionExited("Drivers");
                }


                var LiabilityAvgAgeFactor =
                    StatementExecuted("246", "LiabilityAvgAgeFactor", "LiabilityAvgAgeFactor", "Sum(Drivers, \'LiabilityAgeFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityAgeFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgAgeFactor
                         );


                var LiabilityAvgYearsWithEmployerFactor =
                    StatementExecuted("247", "LiabilityAvgYearsWithEmployerFactor", "LiabilityAvgYearsWithEmployerFactor", "Sum(Drivers, \'LiabilityYearsWithEmployerFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityYearsWithEmployerFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgYearsWithEmployerFactor
                         );


                var LiabilityAvgDrivingExperienceFactor =
                    StatementExecuted("248", "LiabilityAvgDrivingExperienceFactor", "LiabilityAvgDrivingExperienceFactor", "Sum(Drivers, \'LiabilityDrivingExperienceFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityDrivingExperienceFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgDrivingExperienceFactor
                         );


                var LiabilityAvgPointsFactor =
                    StatementExecuted("250", "LiabilityAvgPointsFactor", "LiabilityAvgPointsFactor", "Sum(Drivers, \'LiabilityPointsFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityPointsFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgPointsFactor
                         );


                var LiabilityAvgMinorsFactor =
                    StatementExecuted("251", "LiabilityAvgMinorsFactor", "LiabilityAvgMinorsFactor", "Sum(Drivers, \'LiabilityMinorsFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityMinorsFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgMinorsFactor
                         );


                var LiabilityAvgLicenseRestrictionFactor =
                    StatementExecuted("252", "LiabilityAvgLicenseRestrictionFactor", "LiabilityAvgLicenseRestrictionFactor", "Sum(Drivers, \'LiabilityLicenseRestrictionFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityLicenseRestrictionFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgLicenseRestrictionFactor
                         );


                var LiabilityAvgDriverFactor =
                    StatementExecuted("253", "LiabilityAvgDriverFactor", "LiabilityAvgDriverFactor", "Sum(Drivers, \'LiabilityDriverCoverageFactor\')/Count(Drivers)",
                         () => { return Convert.ToDouble((Sum(Drivers, "LiabilityDriverCoverageFactor"))) / Convert.ToDouble((Count(Drivers))); } // <------- LiabilityAvgDriverFactor
                         );


                var LiabilityBusOwnerAttractScoreFactor =
                    StatementExecuted("254", "LiabilityBusOwnerAttractScoreFactor", "LiabilityBusOwnerAttractScoreFactor", "attractScoreType == \'BusinessOwner\' ? RuleEngineUser_CCI_BusinessOwnersAttractSco" +
            "reFactor(\'AutoLiabilityFactor\', attractScore) : 1",
                         () => { return (bool)((attractScoreType).Equals("BusinessOwner")) ? (RuleEngineUser_CCI_BusinessOwnersAttractScoreFactor("AutoLiabilityFactor", attractScore)) : 1; } // <------- LiabilityBusOwnerAttractScoreFactor
                         );


                var LiabilityCommercialAttractScoreFactor =
                    StatementExecuted("255", "LiabilityCommercialAttractScoreFactor", "LiabilityCommercialAttractScoreFactor", "attractScoreType == \'Commercial\' ? RuleEngineUser_CCI_CommercialAttractScoreFacto" +
            "r(\'AutoLiabilityFactor\', attractScore) : 1",
                         () => { return (bool)((attractScoreType).Equals("Commercial")) ? (RuleEngineUser_CCI_CommercialAttractScoreFactor("AutoLiabilityFactor", attractScore)) : 1; } // <------- LiabilityCommercialAttractScoreFactor
                         );


                var FinalLiabilityFactor =
                    StatementExecuted("256", "FinalLiabilityFactor", "FinalLiabilityFactor", "LiabilityAvgDriverFactor * (LiabilityBusOwnerAttractScoreFactor * LiabilityCommer" +
            "cialAttractScoreFactor)",
                         () => { return Convert.ToDouble((LiabilityAvgDriverFactor)) * Convert.ToDouble((Convert.ToDouble((LiabilityBusOwnerAttractScoreFactor)) * Convert.ToDouble((LiabilityCommercialAttractScoreFactor)))); } // <------- FinalLiabilityFactor
                         );

                ConditionExited("IsLiability");
            }

            return Result;
        }





    }

    public class CommonRuleBook : CompiledRuleBookBase
    {
        public override IEnumerable<InputRequirement> GetInputRequirements()
        {
            yield break;
        }
        protected override RuleBookResult InternalExecute(Dictionary<string, object> inputs)
        {
            return Result;
        }


        public Dictionary<string, object> MikesTestBook(params object[] args)
        {
            return Execute("MikesTestBook", args);
        }

        public Dictionary<string, object> CCI_TierFactor(params object[] args)
        {
            return Execute("CCI_TierFactor", args);
        }

        public Dictionary<string, object> Underwriting_Workstation_Binding_Checklist(params object[] args)
        {
            return Execute("Underwriting_Workstation_Binding_Checklist", args);
        }

        public Dictionary<string, object> Rating_CW(params object[] args)
        {
            return Execute("Rating_CW", args);
        }

        public Dictionary<string, object> Liability_CW(params object[] args)
        {
            return Execute("Liability_CW", args);
        }

        public Dictionary<string, object> DriverGrading(params object[] args)
        {
            return Execute("DriverGrading", args);
        }

        public Dictionary<string, object> DriverGrading_Liability(params object[] args)
        {
            return Execute("DriverGrading_Liability", args);
        }


        #region LookupMethods



        public virtual object RuleEngineUser_CCI_AgeTier(string column, object _Age)
        {
            return Lookup("RuleEngineUser", "CCI_AgeTier", column, _Age);
        }

        public virtual object RuleEngineUser_CCI_Commodities(string column, object _CommodityId)
        {
            return Lookup("RuleEngineUser", "CCI_Commodities", column, _CommodityId);
        }

        public virtual object RuleEngineUser_CCI_CreditTier(string column, object _CreditScore)
        {
            return Lookup("RuleEngineUser", "CCI_CreditTier", column, _CreditScore);
        }

        public virtual object RuleEngineUser_CCI_DrivingExpTier(string column, object _YearsExperience)
        {
            return Lookup("RuleEngineUser", "CCI_DrivingExpTier", column, _YearsExperience);
        }

        public virtual object RuleEngineUser_CCI_NumberMinorsTier(string column, object _NumberOfMinors)
        {
            return Lookup("RuleEngineUser", "CCI_NumberMinorsTier", column, _NumberOfMinors);
        }

        public virtual object RuleEngineUser_CCI_NumberPointsTier(string column, object _NumberOfPoints)
        {
            return Lookup("RuleEngineUser", "CCI_NumberPointsTier", column, _NumberOfPoints);
        }

        public virtual object RuleEngineUser_CCI_TierAdjustmentFactor(string column, object _Fit)
        {
            return Lookup("RuleEngineUser", "CCI_TierAdjustmentFactor", column, _Fit);
        }

        public virtual object RuleEngineUser_CCI_TierFactor(string column, object _Tier)
        {
            return Lookup("RuleEngineUser", "CCI_TierFactor", column, _Tier);
        }

        public virtual object RuleEngineUser_CCI_YearsWithCurrentEmployerTier(string column, object _YearsWithCurrentEmployer)
        {
            return Lookup("RuleEngineUser", "CCI_YearsWithCurrentEmployerTier", column, _YearsWithCurrentEmployer);
        }

        public virtual object RuleEngineUser_CCI_AgeFactor(string column, object _Age)
        {
            return Lookup("RuleEngineUser", "CCI_AgeFactor", column, _Age);
        }

        public virtual object RuleEngineUser_CCI_YearsDrivingExperienceFactor(string column, object _Years)
        {
            return Lookup("RuleEngineUser", "CCI_YearsDrivingExperienceFactor", column, _Years);
        }

        public virtual object RuleEngineUser_CCI_YearsWithCurrentEmployerFactor(string column, object _Years)
        {
            return Lookup("RuleEngineUser", "CCI_YearsWithCurrentEmployerFactor", column, _Years);
        }

        public virtual object RuleEngineUser_CCI_NumberOfPointsFactor(string column, object _Points)
        {
            return Lookup("RuleEngineUser", "CCI_NumberOfPointsFactor", column, _Points);
        }

        public virtual object RuleEngineUser_CCI_NumberOfMinorsFactor(string column, object _Minors)
        {
            return Lookup("RuleEngineUser", "CCI_NumberOfMinorsFactor", column, _Minors);
        }

        public virtual object RuleEngineUser_CCI_BusinessOwnersAttractScoreFactor(string column, object _AttractScore)
        {
            return Lookup("RuleEngineUser", "CCI_BusinessOwnersAttractScoreFactor", column, _AttractScore);
        }

        public virtual object RuleEngineUser_CCI_DriverLicenseRestrictionFactor(string column, object _Restriction)
        {
            return Lookup("RuleEngineUser", "CCI_DriverLicenseRestrictionFactor", column, _Restriction);
        }

        public virtual object RuleEngineUser_CCI_CommercialAttractScoreFactor(string column, object _AttractScore)
        {
            return Lookup("RuleEngineUser", "CCI_CommercialAttractScoreFactor", column, _AttractScore);
        }
        #endregion
    }


}
